// 04myCenter/02set/02changePayPwd/changePayPwd.js
var co = require('../../../resource/js/common.js')
var M = require('../../../resource/js/md5.js')
var ws = require('../../../resource/js/websocket.js')
var app = getApp()
var _this, _data
Page({
  /**
   * 页面的初始数据
   */
  data: {
     showMessage: false,//提示信息
     firstSetPwd: '请输入旧支付密码',
     messageContent: '', //保存时未满足要求提示语
     lastPwd:'',//旧支付密码
     newPwd:'',//新支付密码
     forInput:null,
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
     _this = this
     _data = this.data
     console.log(app.Data)
     _this.updataAppData()
     if (app.Data.userInfo.PayPassword_Is_Set == 0) {
        this.setData({
           firstSetPwd: '第一次不用输入旧密码'     
        })
     }
  },
  updataAppData() {
     if (app.Data.userInfo.PayPassword_Is_Set == 0) {//无密码
        _this.setData({
           forInput: false
        })
     } else {//有密码
        _this.setData({
           forInput: true
        })
     }
  },
   //获取旧支付密码
   inputLastPwd: function (e) {
      var lastPwd = e.detail.value
      _this.setData({
         lastPwd: lastPwd
      })
   },
   //获取新支付密码
   inputNewPwd: function (e) {
      var newPwd = e.detail.value
      _this.setData({
         newPwd: newPwd
      })
   },
   //修改支付密码
   modifyPassword: function () {
      //console.log(1)
      var url = 'jyhs/Usermg/updateInfo'
      var param = {
         User_ID: app.Data.userInfo.User_ID,
      }
      if (app.Data.userInfo.PayPassword_Is_Set == 0) {//无密码
         param.User_PayPassword_New = M.md5(_data.newPwd)
      } else {//有密码
         param.User_PayPassword = M.md5(_data.lastPwd)
         param.User_PayPassword_New = M.md5(_data.newPwd)
      }
      if (_data.newPwd == '') {
         co.toastAllText('新支付密码不能为空')
         return
      } else if (_data.newPwd.length < 6) {
         co.toastAllText('新支付密码长度不能小于6')
         return
      }else {
         co.getShareApi(url, param, function (res) {
            if (res.code == 0) {
               console.log("@@@",res.data)
               co.toastAllText(res.msg)
               app.Data.userInfo = res.data
               setTimeout(function () {
                  var pages = getCurrentPages(),
                     prevPage = pages[pages.length - 2];
                    prevPage.setData({
                     alter: "123"
                    })
                  _this.updataAppData()
                  wx.navigateBack({})
               }, 1000)
            } else {
               co.toastAllText(res.msg)
            }
         })
      }
   },



   //跳转找回密码
   toRetrievePassword: function () {
      wx.navigateTo({
         url: '/04myCenter/02set/02changePayPwd/01retrievePassword/retrievePassword',
      })
   },
   //显示提示信息
   showMessage: function (text) {
      var that = this
      that.setData({
         showMessage: true,
         messageContent: text
      })
      setTimeout(function () {
         that.setData({
            showMessage: true,
            messageContent: text
         })
         setTimeout(function () {
            that.setData({
               showMessage: false,
               messageContent: ''
            })
         }, 3000)
      })
   },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})